package main

import (
	"context"
	"fmt"
	"greeterclient/proto/greeterServer"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	// 1.建立连接
	// credentials,NewclientTLsFromFile: 从输入的证书文件中为客户端构造TLS凭证
	// grpc.withrransportCredentials: 配置连接级别的安全凭证(例，TLS/SSL) ，返回一个DialOption，用于连接服务器。

	grpcClient, err := grpc.Dial("127.0.0.1:9002", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		fmt.Println(err)
		return
	}
	// 2.注册客户端
	client := greeterServer.NewGreeterClient(grpcClient)

	res, err := client.SayHello(context.Background(), &greeterServer.HelloReq{
		Name: "joker",
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%#v", res)
}
